package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here

//        Set<Student> set = new TreeSet<>();
//        set.add(new Student(10001,"a",15));
//        set.add(new Student(10003,"b",15));
//        set.add(new Student(10005,"c",15));
//        set.add(new Student(10004,"ab",15));
//        set.add(new Student(10010,"d",15));
//
//        for (Student s: set) {
//            System.out.println(s.toString());
//        }

        List<Teacher> list = new ArrayList<Teacher>();
        list.add(new Teacher(10001,"a",15));
        list.add(new Teacher(10003,"b",15));
        list.add(new Teacher(10005,"c",15));
        list.add(new Teacher(10004,"ab",15));
        list.add(new Teacher(10010,"d",15));

        //可以在类中实现比较接口的逻辑，在作为参数传入工具类
        Collections.sort(list,new Teacher());

        for (Teacher t: list) {
            System.out.println(t.toString());
        }

        System.out.println("------------------------------------------------");

        //可以现写比较接口的逻辑，利用匿名内部类传入
        Collections.sort(list, new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int i = 0;
                if(o1.getStu_no() < o2.getStu_no()){
                    i = 1;
                }
                if(o1.getStu_no() > o2.getStu_no()){
                    i = -1;
                }

                return i;
            }
        });

        for (Teacher t: list) {
            System.out.println(t.toString());
        }

    }
}
